package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.SysDeviceType;
import com.ruoyi.system.service.ISysDeviceTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备管理Controller
 * 
 * @author 胡化敏
 * @date 2020-06-22
 */
@RestController
@RequestMapping("/type")
public class SysDeviceTypeController extends BaseController
{
    @Autowired
    private ISysDeviceTypeService sysDeviceTypeService;

    /**
     * 查询设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDeviceType sysDeviceType)
    {
        startPage();
        List<SysDeviceType> list = sysDeviceTypeService.selectSysDeviceTypeList(sysDeviceType);
        return getDataTable(list);
    }

    /**
     * 导出设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDeviceType sysDeviceType) throws IOException
    {
        List<SysDeviceType> list = sysDeviceTypeService.selectSysDeviceTypeList(sysDeviceType);
        ExcelUtil<SysDeviceType> util = new ExcelUtil<SysDeviceType>(SysDeviceType.class);
        util.exportExcel(response, list, "type");
    }

    /**
     * 获取设备管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{deviceCode}")
    public AjaxResult getInfo(@PathVariable("deviceCode") Long deviceCode)
    {
        return AjaxResult.success(sysDeviceTypeService.selectSysDeviceTypeById(deviceCode));
    }

    /**
     * 新增设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDeviceType sysDeviceType)
    {
        return toAjax(sysDeviceTypeService.insertSysDeviceType(sysDeviceType));
    }

    /**
     * 修改设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDeviceType sysDeviceType)
    {
        return toAjax(sysDeviceTypeService.updateSysDeviceType(sysDeviceType));
    }

    /**
     * 删除设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceCodes}")
    public AjaxResult remove(@PathVariable Long[] deviceCodes)
    {
        return toAjax(sysDeviceTypeService.deleteSysDeviceTypeByIds(deviceCodes));
    }
}
